package org.springcloud.wisdom.amusement.service.serviceimp;

import org.springcloud.wisdom.amusement.dao.WallDao;
import org.springcloud.wisdom.amusement.entity.Wall;
import org.springcloud.wisdom.amusement.service.IWallService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WallServiceImp implements IWallService {
    @Autowired
    WallDao wallDao;

    @Override
    public Boolean reportWallMsg(Integer id) {
        if (id == null){
            return  false;
        }
        Wall wall = wallDao.getOneWall(id);
        //如果被举报超过十次直接被删除，管理员可以查看这条信息
        if (wall.getReport() >= 9) {
            //进来这次是第十次
            wallDao.reportWallMsg(id);
            return wallDao.overDeleteMsg(id) > 0;
        }
        //审核通过的信息 被举报不再进行再次审核
        if (wall.getIspass() == 1) {
            return true;
        } else {
            return wallDao.reportWallMsg(id) > 0;
        }
    }

    @Override
    public Boolean addWallMsg(Wall wall) {
        if (wall.getName().trim().length()==0 ||wall.getName()==null){
            return false;
        }
        if (wall.getMsg().trim().length()==0 ||wall.getMsg()==null){
            return false;
        }

        return wallDao.addWallMsg(wall) > 0;
    }

    @Override
    public Boolean judgeWallMsg(Integer id) {
        if (id == null){
            return false;
        }
        return wallDao.judgeWallMsg(id) > 0;
    }

    @Override
    public Boolean recoverDeleteMsg(Integer id) {
        if (id == null){
            return  false;
        }
        return wallDao.recoverDeleteMsg(id) > 0;
    }

    @Override
    public Boolean deleteWallMsg(Integer id) {
        if (id == null){
            return  false;
        }
        return wallDao.deleteWallMsg(id) > 0;
    }

    @Override
    public List<Wall> getAllWallMsg() {
        return wallDao.getAllWallMsg();
    }

    @Override
    public List<Wall> getAllReportMsg() {
        return wallDao.getAllReportMsg();
    }

    @Override
    public List<Wall> getDelWallMsg() {
        return wallDao.getDelWallMsg();
    }
}
